package com.hdu.other.tanxin;

import java.util.*;

public class lc1553 {


    class Solution {
        private final Map<Integer,Integer> CACHE_MAP = new HashMap<>();
        public int minDays(int n) {
            CACHE_MAP.clear();
            return f(n);
        }

        int f(int n)
        {
            if (n <= 1)
            {
                return n;
            }
            if (CACHE_MAP.containsKey(n))
            {
                return CACHE_MAP.get(n);
            }
            int p1 = n % 3 + 1 + f(n / 3);
            int p2 = n % 2 + 1 + f(n / 2);
            CACHE_MAP.put(n, Math.min(p1, p2));
            return CACHE_MAP.get(n);
        }
    }
}
